package com.dongnam.quanly.common.controller;

import java.util.List;

import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.dao.PhieuNhapXuatDao;
import com.dongnam.quanly.common.exceptions.DatabaseException;
import com.dongnam.quanly.common.model.PhieuNhapXuat;
import com.dongnam.quanly.common.persistence.HibernateUtil;

public class PhieuNhapXuatController extends GenericController<PhieuNhapXuat, String> {

	private static final Logger logger = LoggerFactory.getLogger(PhieuNhapXuatController.class);

	public PhieuNhapXuatController() {
		super(new PhieuNhapXuatDao());
		// TODO Auto-generated constructor stub
	}

	@Override
	public PhieuNhapXuatDao getDao() {
		// TODO Auto-generated method stub
		return (PhieuNhapXuatDao) dao;
	}

	public List<String> getListPNX(String sodonhang) throws DatabaseException {
		boolean isTransacted = HibernateUtil.getCurrentSession().getTransaction().isActive();
		Session session = isTransacted ? HibernateUtil.getCurrentSession() : HibernateUtil.startCurrentSession();
		try {
			List<String> list = getDao().getListPNX(sodonhang);
			if (!isTransacted) {
				session.getTransaction().commit();
			}
			return list;
		} catch (Throwable e) {
			rollbackConditionally(isTransacted, session);
			logger.debug("exception", e);
			throw new DatabaseException(e);
		}

	}

}
